package flexconsole.controls {
	
	import flash.display.Sprite;
	
	import mx.controls.DataGrid;
	
	/**
	 * DataGrid extension to support custom row colors.
	 *
	 * @see mx.controls.DataGrid
	 */
	public class AdvDataGrid extends DataGrid {
		
		/**
		 * User defined function to calculate the row color for a specific row.
		 *
		 * <p>This function requires the following signature:
		 * <code>function rowColorFunction(item:Object, rowIndex:int, dataIndex:int, color:uint):uint</code>
		 * </p>
		 */
		public var rowColorFunction:Function;
		
		public function AdvDataGrid() {
			super();
		}
		
		/**
		 * 	@private
		 */
		override protected function drawRowBackground(s:Sprite, rowIndex:int, y:Number, height:Number, color:uint, dataIndex:int):void {
			if (rowColorFunction is Function && dataProvider != null) {
				var item:Object;
				
				if (dataIndex < dataProvider.length) {
					item = dataProvider[dataIndex];
				}
				
				if (item) {
					color = rowColorFunction(item, rowIndex, dataIndex, color);
				}
			}
			super.drawRowBackground(s, rowIndex, y, height, color, dataIndex);
		}
	
	}
}